package com.dolphin.serviceorder.controller;


import com.dolphin.common.constant.HeadParamConstants;
import com.dolphin.common.dto.OrderInfo;
import com.dolphin.common.dto.ResponseResult;
import com.dolphin.common.request.DriverGrabRequest;
import com.dolphin.common.request.OrderRequest;
import com.dolphin.serviceorder.service.GrabService;
import com.dolphin.serviceorder.service.OrderInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/order")
@Slf4j
public class OrderInfoController {
    @Autowired
    OrderInfoService orderInfoService;

    /**
     * 添加订单
     * @param orderRequest
     * @return
     */
    @PostMapping("/add")
    public ResponseResult add(@RequestBody OrderRequest orderRequest, HttpServletRequest httpServletRequest) {
//        String deviceCode = httpServletRequest.getHeader(HeadParamConstants.DEVICE_CODE);
//        orderRequest.setDeviceCode(deviceCode);
//        log.info("service-order  header deviceCode{}", deviceCode);


        log.info("service-order下单请求：{}", orderRequest.getAddress());
        return orderInfoService.add(orderRequest);
    }

    /**
     * 创建预约订单
     * @param orderRequest
     * @return
     */
    @PostMapping("/book")
    public ResponseResult book(@RequestBody OrderRequest orderRequest, HttpServletRequest httpServletRequest) {

        log.info("service-order下单请求：{}", orderRequest.getAddress());
        return orderInfoService.book(orderRequest);
    }


    /**
     * 去接乘客
     * @param orderRequest
     * @return
     */
    @PostMapping("/to-pick-up-passenger")
    public ResponseResult toPickUpPassenger(@RequestBody OrderRequest orderRequest) {

        return orderInfoService.toPickUpPassenger(orderRequest);
    }

    /**
     * 到达乘客上车点
     * @param orderRequest
     * @return
     */
    @PostMapping("/arrive-departure")
    public ResponseResult arriveDeparture(@RequestBody OrderRequest orderRequest) {


        return orderInfoService.arriveDeparture(orderRequest);
    }

    /**
     * 司机接到乘客  乘客上车
     * @param orderRequest
     * @return
     */
    @PostMapping("/pick-up-passenger")
    public ResponseResult pickUpPassenger(@RequestBody OrderRequest orderRequest) {

        return orderInfoService.pickUpPassenger(orderRequest);
    }

    /**
     * 乘客到达目的地  乘客下车
     * @param orderRequest
     * @return
     */
    @PostMapping("/passenger-getoff")
    public ResponseResult passengerGetOff(@RequestBody OrderRequest orderRequest) {

        return orderInfoService.passengerGetOff(orderRequest);
    }

    /**
     * 司机发起收款
     * @param orderRequest
     * @return
     */
    @PostMapping("/push-pay-info")
    public ResponseResult pushPayInfo(@RequestBody OrderRequest orderRequest) {
        return orderInfoService.pushPayInfo(orderRequest);
    }

    /**
     * 支付完成
     * @param orderRequest
     * @return
     */
    @PostMapping("/pay")
    public ResponseResult pay(@RequestBody OrderRequest orderRequest) {
        return orderInfoService.pay(orderRequest);
    }

    /**
     * 取消订单
     * @param orderId
     * @param identity
     * @return
     */
    @PostMapping("/cancel")
    public ResponseResult cancel(Long orderId,String identity) {
        return orderInfoService.cancel(orderId,identity);
    }
    /**
     * 订单详情
     * @param orderId
     * @return
     */
    @GetMapping("/detail")
    public ResponseResult<OrderInfo> detail(Long orderId){
        return orderInfoService.detail(orderId);
    }
    @GetMapping("/current")
    public ResponseResult current(String phone , String identity){
        return orderInfoService.current(phone , identity);
    }


    @Autowired
    @Qualifier("grabByRedissonBasicService")
    private GrabService grabService;
    /**
     * 司机抢单
     * @param driverGrabRequest
     * @return
     */
    @PostMapping("/grab")
    public ResponseResult<OrderInfo> drvierGrab(@RequestBody DriverGrabRequest driverGrabRequest){

        return grabService.grab(driverGrabRequest);
    }



}